/*
 * @Description: js 对json数组按照几个字段排序
 * @Version: 1.0
 * @Autor: wq
 * @Date: 2021-08-27 16:06:17
 * @LastEditors: wq
 * @LastEditTime: 2021-08-27 16:08:49
 */
function sortObjectArray(objArr, keyArr, type) {
  if (type !== undefined && type !== "asc" && type !== "desc") {
    return "error";
  }
  let order = 1;
  if (type !== undefined && type === "desc") {
    order = -1;
  }
  let key = keyArr[0];
  objArr.sort(function (objA, objB) {
    if (objA[key] > objB[key]) {
      return order;
    } else if (objA[key] < objB[key]) {
      return 0 - order;
    } else {
      return 0;
    }
  });
  for (let i = 1; i < keyArr.length; i++) {
    let key = keyArr[i];
    objArr.sort(function (objA, objB) {
      for (let j = 0; j < i; j++) {
        if (objA[keyArr[j]] !== objB[keyArr[j]]) {
          return 0;
        }
      }
      if (objA[key] > objB[key]) {
        return order;
      } else if (objA[key] < objB[key]) {
        return 0 - order;
      } else {
        return 0;
      }
    });
  }
  return objArr;
}

let sourceData = [
    { col_0: "粗抛槽", col_1: "初配", col_2: "温度", value: "80", unit: "" },
    { col_0: "粗抛槽", col_1: "初配", col_2: "时间", value: "9999", unit: "" },
    { col_0: "粗抛槽", col_1: "补液", col_2: "CDI", value: "1000", unit: "" },
    { col_0: "粗抛槽", col_1: "补液", col_2: "HDI", value: "9000", unit: "" },
    { col_0: "粗抛槽", col_1: "补液", col_2: "KOH", value: "800", unit: "" },
    { col_0: "粗抛槽", col_1: "初配", col_2: "KOH", value: "40000", unit: "" },
  
    { col_0: "预清洗槽", col_1: "初配", col_2: "温度", value: "70", unit: "" },
    { col_0: "制绒槽1", col_1: "初配", col_2: "温度", value: "82", unit: "" },
    { col_0: "制绒槽2", col_1: "初配", col_2: "温度", value: "82", unit: "" },
    { col_0: "制绒槽3", col_1: "初配", col_2: "温度", value: "82", unit: "" },
    { col_0: "慢提拉槽", col_1: "", col_2: "温度", value: "70", unit: "" },
    { col_0: "风干槽1", col_1: "", col_2: "温度", value: "90", unit: "" },
    { col_0: "风干槽2", col_1: "", col_2: "温度", value: "90", unit: "" },
    { col_0: "风干槽3", col_1: "", col_2: "温度", value: "90", unit: "" },
    { col_0: "风干槽4", col_1: "", col_2: "温度", value: "90", unit: "" },
    { col_0: "预清洗槽", col_1: "初配", col_2: "时间", value: "135", unit: "" },
    { col_0: "制绒槽1", col_1: "初配", col_2: "时间", value: "430", unit: "" },
    { col_0: "制绒槽2", col_1: "初配", col_2: "时间", value: "430", unit: "" },
    { col_0: "制绒槽3", col_1: "初配", col_2: "时间", value: "430", unit: "" },
    { col_0: "臭氧槽", col_1: "初配", col_2: "时间", value: "120", unit: "" },
    { col_0: "酸洗1槽", col_1: "初配", col_2: "时间", value: "", unit: "" },
    { col_0: "酸洗1槽", col_1: "初配", col_2: "时间", value: "", unit: "" },
    { col_0: "慢提拉槽", col_1: "", col_2: "时间", value: "10", unit: "" },
    { col_0: "风干槽1", col_1: "", col_2: "时间", value: "560", unit: "" },
    { col_0: "风干槽2", col_1: "", col_2: "时间", value: "560", unit: "" },
    { col_0: "风干槽3", col_1: "", col_2: "时间", value: "560", unit: "" },
    { col_0: "风干槽4", col_1: "", col_2: "时间", value: "560", unit: "" },
    { col_0: "预清洗槽", col_1: "补液", col_2: "CDI", value: "1000", unit: "" },
    { col_0: "预清洗槽", col_1: "补液", col_2: "H2O2", value: "500", unit: "" },
    { col_0: "预清洗槽", col_1: "补液", col_2: "HDI", value: "2000", unit: "" },
    { col_0: "预清洗槽", col_1: "补液", col_2: "KOH", value: "90", unit: "" },
    { col_0: "制绒槽1", col_1: "补液", col_2: "ADDI", value: "200", unit: "" },
    { col_0: "制绒槽1", col_1: "补液", col_2: "HDI", value: "10000", unit: "" },
  ];
sortObjectArray(sourceData, ["col_0", "col_1"], "desc");
